package org.yoome.jtools.distributelock;

import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.core.annotation.AnnotationUtils;

import java.lang.reflect.Method;
import java.util.Objects;

public class LockPointcut extends StaticMethodMatcherPointcut {
    @Override
    public boolean matches(Method method, Class<?> subClass) {
        AutoDistributeLock annotation
                = AnnotationUtils.findAnnotation(method, AutoDistributeLock.class);
        if (Objects.nonNull(annotation)) {
            return true;
        }
//        try {
//            Method subMethod = subClass.getMethod(method.getName(), method.getParameterTypes());
//            annotation = AnnotationUtils.findAnnotation(subMethod, AutoDistributeLock.class);
//            if (Objects.nonNull(annotation)) {
//                return true;
//            }
//        } catch (NoSuchMethodException e) {
//            e.printStackTrace();
//        }
        return false;
    }
}
